package data.promotion;
import java.util.Calendar;
import data.ItemData;
import data.ItemRecord;
import data.Record;


public class ItemDiscountRecord extends Record {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8971288225323768134L;

	private String item_id;
	
	private double special_price;
	
	private Calendar start_time;
	
	private Calendar end_time;
	
	
	public ItemDiscountRecord(){
		
	}
	
	
	public ItemDiscountRecord(String item_id,double special_price,Calendar start_time,Calendar end_time){
		this.set(item_id, special_price, start_time, end_time);
	}
	
	
	public void set(String item_id,double special_price,Calendar start_time,Calendar end_time){
		this.item_id=item_id;
		this.special_price=special_price;
		this.start_time=start_time;
		this.end_time=end_time;
	}
	
	
	
	public String getItemID(){
		return item_id;
	}
	
	public double getSpecialPrice(){
		return special_price;
	}
	
	public Calendar getStartTime(){
		return start_time;
	}
	
	public Calendar getEndTime(){
		return start_time;
	}
	
	
	public void setItem(ItemRecord item){
		if(this.isDuringTime()&&item.getID().equals(item_id)){
			item.setSpecialPrice(special_price);
		}
	}
	
	
	public void setItemList(ItemData itemList){
		ItemRecord item=itemList.getItemByID(item_id);
		if(this.isDuringTime()&&item!=null){
			item.setSpecialPrice(special_price);
		}
	}
	
	
	
	public boolean isDuringTime(){
		Calendar time=Calendar.getInstance();
		return this.isDuringTime(time);
	}
	
	public boolean isDuringTime(Calendar time){
	    return (time.after(start_time)&&time.before(end_time));
	}
}
